package com.xscha.soyue.common.core.utils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * Base64工具类
 *
 * @author Vondser
 * @version V2024.1.0
 */
public class Base64Util {

	public Base64Util() {
	}

	public static byte[] decryptBASE64(byte[] encryptedData) {
		return Base64.getDecoder().decode(encryptedData);
	}

	public static byte[] decryptBASE64(String encryptedData) {
		return decryptBASE64(encryptedData.getBytes(StandardCharsets.UTF_8));
	}

	public static String decryptToString(String encryptedData) {
		return decryptToString(encryptedData.getBytes(StandardCharsets.UTF_8));
	}

	public static String decryptToString(byte[] encryptedData) {
		return new String(decryptBASE64(encryptedData));
	}

	public static byte[] encryptBASE64(byte[] decryptedData) {
		return Base64.getEncoder().encode(decryptedData);
	}

	public static byte[] encryptBASE64(String plaintext) {
		return encryptBASE64(plaintext.getBytes(StandardCharsets.UTF_8));
	}

	public static String encryptToString(String plaintext) {
		return encryptToString(plaintext.getBytes(StandardCharsets.UTF_8));
	}

	public static String encryptToString(byte[] plainByteArr) {
		return new String(encryptBASE64(plainByteArr));
	}

}
